import 'package:camerawesome/camerawesome_plugin.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:getx_learn/app/modules/weichat_post/modules/post/constant/config.dart';
import 'package:getx_learn/app/modules/weichat_post/widgets/camera/camera.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';

/// 执行拍摄动作
class Dupicker {
  /// 展示功能选择底部弹出框
  static Future<T?> showModalSheet<T>(BuildContext context, {Widget? child}) {
    // 原生的底部弹出框
    return showModalBottomSheet<T>(
        context: context,
        backgroundColor: Colors.white,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(10),
            topRight: Radius.circular(10),
          ),
        ),
        builder: (context) {
          return Padding(
            padding: const EdgeInsets.symmetric(vertical: 15),
            child: SizedBox(
              width: MediaQuery.of(context).size.width,
              child: child ?? SizedBox.shrink(),
            ),
          );
        });
  }

  /// 相册选择
  /// @param context 上下文
  /// @param selectedAssets 已选中的图片
  /// @param maxAssets 最大的可选数量
  /// @param requestType 可选的媒体类型
  static Future<List<AssetEntity>?> assets({
    required BuildContext context,
    List<AssetEntity>? selectedAssets,
    int maxAssets = maxAssets,
    RequestType requestType = RequestType.image,
  }) async {
    AssetPickerConfig pickerConfig = AssetPickerConfig(
      selectedAssets: selectedAssets,
      maxAssets: maxAssets,
      requestType: requestType,
    );

    final List<AssetEntity>? result =
        await AssetPicker.pickAssets(context, pickerConfig: pickerConfig);
    if (result == null) {
      return null;
    }
    return result;
  }

  /// 拍摄图片
  /// @param context 上下文
  static Future<AssetEntity?> takePhoto(BuildContext context) async {
    // camerawesome 库的使用
    final AssetEntity? result = await Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) {
          return CameraPage(
            captureMode: CaptureMode.photo,
          );
        },
      ),
    );
    return result;
  }

  /// 拍摄视频
  /// @param context 上下文
  static Future<AssetEntity?> taskVideo(BuildContext context) async {
    // camerawesome 库的使用
    final AssetEntity? result = await Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) {
          return CameraPage(
            captureMode: CaptureMode.video,
            maxVideoDuration: Duration(seconds: 30),
          );
        },
      ),
    );
    return result;
  }
}
